@extends('layout.wechat_frame')

@section('main')
    <header class="mui-bar mui-bar-nav">
        <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
        <h1 class="mui-title">报价详细</h1>
    </header>

    <div class="mui-content">
        <ul class="mui-table-view mui-table-view-striped mui-table-view-condensed">
            <li class="mui-table-view-cell">

                <?php
                $goods = json_decode($bid->goods_static);
                ?>
                <h5 class="ips-text-blue">{{ $goods->name }}采购标书，报价在{{ $bid->offer_stop }}结束</h5>
                <div class="mui-table">
                    <div class="mui-table-cell mui-col-xs-10">
                        <h4>质量指标</h4>

                        <textarea id="textarea" class="ips-textarea" rows="5" placeholder="" readonly>{{ $goods->quality_standard }}</textarea>

                    </div>
                </div>
            </li>
        </ul>
    </div>

    @foreach ($demands as $k=>$demand)
        <?php
        $assign_rule = json_decode($demand->assign_rule);
        $assign_rule_data = $assign_rule->rules;
        $assign_rule_data = json_decode($assign_rule_data, true);
        $assign_rule_data = implode('%；', $assign_rule_data).'%';
        ?>

    <div class="mui-content ips-mui-content-no-top">
        <ul class="mui-table-view mui-table-view-striped mui-table-view-condensed">
            <li class="mui-table-view-cell mui-collapse">
                <h5 ><span class="ips-span-first-long">公司名/交货地点</span><span>采购数量</span></h5>
                <a class="mui-navigate-right" href="#"><h5><span class="ips-span-first-long">{{ $demand->company->name }}</span><span>{{ strval((float)$demand->quantity) }} {{ $goods->unit }}</span></h5></a>
                <div class="mui-collapse-content">

                    <?php
                    // lvze add 20160908 取得 到货方式 交货地点
                    // 如果交货方式中没有设定地点 则显示 公司交货地点
                    $delivery_mode = \App\DeliveryMode::orderBy('created_at')->whereNull('deleted_at')->where('id', $demand->delivery_mode_id)->first();
                    ?>
                    @if(!empty($delivery_mode) and !($delivery_mode->delivery_place))
                        <h5 ips-row-h5>交货地点：{{ $delivery_mode->delivery_place}}</h5>
                    @else
                        <h5 ips-row-h5>交货地点：{{ $demand->company->delivery_address }}</h5>
                    @endif

                </div>
            </li>

            <?php
            $current_offers = $demand->offer()->with('supplier.supplier')->orderBy(DB::raw('"price"+"delivery_costs"'))->orderBy('updated_at', 'asc')->whereNull('reason')->get();
            $my_offer = $demand->offer()->where('price', '>', 0)->where('user_id', auth()->user()->id)->first();
            ?>

            @if ($bid->offer_stop < $datetime)
                @if(!empty($my_offer))
                    <li class="mui-table-view-cell mui-collapse">
                        <h5 ><span class="ips-span-first-long">单位名称</span><span>我的报价</span></h5>
                        <a class="mui-navigate-right" href="#"><h5 class="mui-ellipsis"><span class="ips-span-first-long">{{ auth()->user()->supplier->name }}</span><span>{{ strval($my_offer->price + $my_offer->delivery_costs) }}</i> 元/{{ $goods->unit }}</span></h5></a>
                        <div class="mui-collapse-content">
                            <h5 class="mui-ellipsis"><span class="ips-span-first">最低成交量</span><span>{{ strval((float)$my_offer->quantity_floor) }}</i> {{ $goods->unit }}</span></h5>
                            <h5 class="mui-ellipsis"><span class="ips-span-first">最低成交量</span><span>{{ strval((float)$my_offer->quantity_caps) }}</i> {{ $goods->unit }}</span></h5>
                            <h5 class="mui-ellipsis"><span class="ips-span-first">成交量</span><span>{{ strval((float)$my_offer->quantity) }}</i> {{ $goods->unit }}</span></h5>
                            <h5 class="mui-ellipsis"><span class="ips-span-first">报价时间</span><span>{{ $my_offer->updated_at }}</span></h5>
                            @if ($demand->is_cancel)
                                <h5 class="mui-ellipsis"><span class="ips-span-first-long ips-text-red">报价供应商未满，按规定作流标处理</span><span></span></h5>
                            @endif
                        </div>
                    </li>
                @endif


                @if (count($current_offers) == 0)
                    <li class="mui-table-view-cell">
                        <div class="mui-table">
                            <div class="mui-table-cell mui-col-xs-10">
                                <h5 >无人报价</h5>
                            </div>
                        </div>
                    </li>
                @else
                    @foreach($current_offers as $k => $current_offer)
                        @if($current_offer->quantity > 0/* or $current_offer->user_id == $current_user->id*/)
                                <li class="mui-table-view-cell">
                                    <div class="mui-table">
                                        <div class="mui-table-cell mui-col-xs-10">
                                            @if (!is_null($current_offer->reason))
                                                <h5 ><span class="ips-span-first-long">中标供应商</span><span>不参与报价理由</span></h5>
                                                <h5 class="mui-ellipsis"><span class="ips-span-first-long">{{ $current_offer->user_id == $current_user->id ? $current_offer->supplier->supplier->name : '**********' }}</span><span>{{ $current_offer->reason }}</span></h5>
                                                @if ($demand->is_cancel)
                                                    <h5 class="mui-ellipsis"><span class="ips-span-first-long ips-text-red">该供应商选择了不参与报价</span><span></span></h5>
                                                @endif
                                            @else
                                                <h5 ><span class="ips-span-first-long">中标供应商</span><span></span></h5>
                                                <h5 class="mui-ellipsis"><span class="ips-span-first-long">{{ $current_offer->user_id == $current_user->id ? $current_offer->supplier->supplier->name : '**********' }}</span><span>{{ strval($current_offer->price + $current_offer->delivery_costs) }}</i> 元/{{ $goods->unit }}</span></h5>
                                                @if ($demand->is_cancel)
                                                    <h5 class="mui-ellipsis"><span class="ips-span-first-long ips-text-red">报价供应商未满，按规定作流标处理</span><span></span></h5>
                                                @endif
                                             @endif
                                        </div>
                                    </div>
                                </li>
                        @endif
                    @endforeach
                @endif
            @endif
        </ul>
    </div>
    @endforeach
@section('js')
@stop